package com.example.stream;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @author xiejp on 2022/5/10
 * 请按照给出的数据,找出同时满足以下条件的用户,也即以下条件全部满足
 * 偶数ID切年龄大于24且用户名转为大写且用户名字母倒排序
 * 只输出一个用户名字
 */
public class StreamDemo {
    public static void main(String[] args) {
        User u1 = new User(11, "a", 23);
        User u2 = new User(12, "b", 24);
        User u3 = new User(13, "c", 25);
        User u4 = new User(14, "d", 26);
        User u5 = new User(16, "e", 27);
        List<User> users = Arrays.asList(u1, u2, u3, u4, u5);
        users.stream()
                .filter(x -> x.getId() % 2 == 0)
                .filter(y -> y.getAge() > 24)
                .map(z->z.getUsername().toUpperCase()).sorted((o1, o2) -> {
                    return o2.compareTo(o1);
                }).limit(1).forEach(System.out::println);



        //Function<String, Integer> function = s -> {
        //    return s.length();
        //};
        //System.out.println(function.apply("111"));
        //
        //Predicate<String> predicate = (s)->{
        //    return s.isEmpty();
        //};
        //predicate.test("122");
    }
}

@Data
@NoArgsConstructor
@AllArgsConstructor
class User {
    private Integer id;
    private String username;
    private int age;
}